// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/user/api/SysRegionApi'

import ComClass from '@api/ComQuery'
import TreeClass from '@api/user/model/SysRegionDto'
import DelClass from '@api/user/model/SysRegionDeleteReq'

const AddClass = TreeClass
const EditClass = TreeClass

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 结构树 —————————————————————————————— //

  async getTree(treeParam, TIP = '查询结构树') {
    const DTO = CORE.grpcDTO(TreeClass, treeParam, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'sysRegionQuery', DTO)
    return resp.content || []
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '新增') {
    const DTO = CORE.grpcDTO(AddClass, one)
    await CORE.grpc(TIP, CLIENT, 'sysRegionSave', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  async edit(one, TIP = '修改') {
    const DTO = CORE.grpcDTO(EditClass, one)
    await CORE.grpc(TIP, CLIENT, 'sysRegionUpdate', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async del({ id }, TIP = '删除') {
    const DTO = CORE.grpcDTO(DelClass, { ids: id })
    await CORE.grpc(TIP, CLIENT, 'sysRegionDelete', DTO)
    return CORE.grpcOK(TIP)
  },
}
